#ifndef EXECUTOR_H
#define EXECUTOR_H
#include "downloadtablemodel.h"
#include <QObject>
#include <QMap>
#include <QFile>
#include <QVariant>
#include <QNetworkAccessManager>

static QNetworkAccessManager manager;

class Executor: public QObject
{
    Q_OBJECT
public:
    Executor(DownloadTableModel *);
    DownloadTableModel * model;
    QMap <int,QNetworkReply*> idToReply;
public slots:
    void submitTask(int id, const QString& fileName, const QString &URL, int priority);
    void cancelTask(int id);
};

class ResponseHandler:public QObject
{
    Q_OBJECT
    QNetworkReply * reply;
    QFile * out;
    Executor * executor;
    int id;
public:
    ResponseHandler(QNetworkReply * reply, QFile *out, Executor *executor, int id);
public slots:
    void newData();
    void done();
    void progress(qint64 read, qint64 all);
signals:
    void modify(int,int,QVariant);
};
#endif // EXECUTOR_H
